package com.study.java8;

import java.util.Objects;
import java.util.function.Predicate;

/**
 * @author ysy
 * @version 1.0
 * @Title: PredicateTest
 * @Note <b>ProjectName:</b> cusc-venus
 * <br><b>PackageName:</b> com.cusc.venus.acc.center.util
 * <br><b>ClassName:</b>
 * <br><b>Date:</b>
 */
public class PredicateTest {

    public static void main(String[] args) {

        // 断言型函数式接口：传入一个参数，返回一个布尔值
        Predicate<Integer> predicate = t -> t > 0;
        boolean test = predicate.test(1);
        System.out.println(test);

        // 默认方法and
        Predicate<String> predicate1 = s -> s.length() > 0;
        Predicate<String> predicate2 = Objects::nonNull;
        test = predicate1.and(predicate2).test("&&测试");
        System.out.println(test);

        // 默认方法or
        predicate1 = s -> false;
        predicate2 = Objects::nonNull;
        test = predicate1.or(predicate2).test("||测试");
        System.out.println(test);

        // 默认方法negate：取反
        Predicate<String> predicate3 = s -> s.length() > 0;
        boolean result = predicate3.negate().test("取反");
        System.out.println(result);

        // 默认方法isEqual
        boolean test1 = Predicate.isEqual("test").test("test");
        boolean test2 = Predicate.isEqual("test").test("equal");
        System.out.println(test1);   //true
        System.out.println(test2);   //false
    }
}
